/**
 * 
 * @brief  global_variables.h
 * @param  None
 * 
 * @author xhq
 * @date   2024/11/05
 * 
 */
#ifndef __SRC_GLOBAL_VARIABLES_H__
#define __SRC_GLOBAL_VARIABLES_H__

/* include */
#include <stdio.h>
#include <math.h>
#include <bits/types.h>
#include <pthread.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <semaphore.h>
#include <sys/time.h>

#include "typedef.h"
 
/* define */
/* 定义arm软件版本名称，mmv-radar为雷达类型，0001为版本序号，20241122为程序编译日期 */
#define ARM_VERSION           "mmv-radar-0001-20241122"

#define APP_NAME              "mmv_lidar"
#define SET_ERROR_CODE(ret, idx) do { ret |= (1 << idx); } while (0);
#define IS_EXIST_ERROR(ret, idx) (ret & (1 << idx))
#define RETURN_ERROR_CODE(ret, info) do { if (ret)\
        printf("[info]\"%s\" return error! (error-code:%0#10x)\n", (char *)&info, ret); return ret;} while (0);

#define MEMBER_NUM_OF_SECTION(section_struct_name) ((sizeof(section_struct_name) - sizeof(struct section_info)) / sizeof(struct member_info))

#define   RAW_DATA_FRAM_NUM                        1        // 原始数据帧数

/* global variables */
#define GLOBAL_VARIABLES
#ifndef GLOBAL_VARIABLES
#define G_EXT
#define GLOBAL_VARIABLES
#else
#define G_EXT extern
#endif

//定义配置文件的名称
#define RF_FAR_USR_CONFIG_JSON_FILE     "rf_far_usr_config.json"
#define RF_NEAR_USR_CONFIG_JSON_FILE     "rf_near_usr_config.json"
#define FAR_RF_EN 
//#define NEAR_RF_EN

/* 线程pid */
G_EXT pthread_t           g_pthread_pid[PTHREAD_NUM_MAX];
G_EXT socket_info_type    g_socket_info[SOCKET_TYPE_MAX];      // socket global param
G_EXT net_info_type       g_net_info;                          // net global param

/* semaphore */
G_EXT sem_t               g_data_pro_semaphore;                // 数据处理信号量
G_EXT sem_t               g_dsp_pro_semaphore;                 // dsp数据处理信号量
G_EXT sem_t               g_mipi_add_ssd_semaphore;            // 将mipi数据保存到ssd信号量
G_EXT sem_t               g_mipi_send_up_semaphore;            // 将mipi数据发送至上位机信号量
G_EXT sem_t               g_mipi_send_res_semaphore;           // 上传mipi数据收到回复信号量
G_EXT sem_t               g_dsp_pro_comlete_semaphore;         // dsp数据处理完成信号量
G_EXT sem_t               g_track_process_semaphore;           // 追踪算法处理信号量

G_EXT pthread_mutex_t     g_rf_semaphore;                      // 射频参数互斥锁
G_EXT pthread_mutex_t     g_ini_semaphore;                     // ini文件操作互斥锁
G_EXT pthread_mutex_t     g_net_param_semaphore;               // 网络参数互斥锁
G_EXT pthread_mutex_t     g_net_send_semaphore;                // 网络发送互斥锁
G_EXT pthread_mutex_t     g_dsp_param_semaphore;               // dsp参数配置互斥锁
G_EXT pthread_mutex_t     g_Mutext_mipi_add_ssd;               // 将mipi数据保存到ssd队列互斥锁
G_EXT pthread_mutex_t     g_Mutext_mipi_send_up[MIPI_CHANNEL_MAX]; // 将mipi数据发送至上位机队列互斥锁,一个mipi数据接收线程对应一个队列对应一个锁
 // 针对四个mipi接收线程共同维护的接收mipi数据计数值的锁
 G_EXT pthread_mutex_t g_Mutext_mipi_recv_cnt;   


/* 调试参数 */
G_EXT uint32_t            g_arm_debug_param[10];                // arm调试参数
G_EXT uint32_t            g_dsp_debug_param[10];                // dsp调试参数

/* sys param */
G_EXT sys_info_type       g_sys_info;

/* sys status */
G_EXT device_status_type  g_device_status;                      // 设备状态结构体

/* 原始数据 */
G_EXT fram_raw_data_info_type   g_fram_raw_data_info;                           // fram数据信息
G_EXT fram_raw_data_type  g_fram_raw_data[RAW_DATA_FRAM_NUM];                   // 原始fram数据， N个

/* 存放发送到上位机的mipi数据，一个mipi数据接收线程对应一个队列 */
G_EXT STRUCT_MIPI g_mipi_to_up_queue[MIPI_CHANNEL_MAX];

// 发送原始mipi数据至上位机标志,1--开始上传,0--停止上传
G_EXT uint32_t g_mipi_data_upload_flag;

// mipi数据上传后回复是否成功标识位，0--成功；1--失败
G_EXT uint8_t g_mipi_upload_status;

/* 已检测的目标信息 */
G_EXT object_info_type  g_object_info;

G_EXT uint32_t g_mipi_frame_index_rev;

/*********test************/
G_EXT struct timespec g_timespec_start;
G_EXT struct timespec g_timespec_end;

#endif
